package com.wang.immutable;

import java.util.Iterator;
import java.util.Set;

/**
 * Set
 * @author yandong
 */
public class ImmutableDemo2 {
    public static void main(String[] args) {
        /*
         * 创建不可变的Set集合
         * {"张三", "李四", "王五", "赵六"}
         */
        Set<String> set = Set.of("张三", "李四", "王五", "赵六");

        // for-each遍历
        for (String name : set) {
            System.out.println(name);
        }
        System.out.println("===========================");

        // for循环遍历
        for (int i= 0; i < set.size(); i++) {
            System.out.println(set.toArray()[i]);
        }
        System.out.println("===========================");

        // 迭代器遍历
        Iterator<String> iterator = set.iterator();
        while (iterator.hasNext()) {
            System.out.println(iterator.next());
        }
    }

}
